//
//  PCUserAlbumModel.m
//  PhotoCircle
//
//  Created by GL on 15/12/18.
//  Copyright © 2015年 wujungao. All rights reserved.
//

#import "PCUserAlbumModel.h"
#import "NSDate+Convenience.h"

#define KEY_Album_UUID          @"uuid"
#define KEY_Album_Photos        @"photos"
#define KEY_Album_Date          @"created_at"

@interface PCUserAlbumModel()

@end

@implementation PCUserAlbumModel

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super initWithDictionary:dict];
    if (self) {
        
        if (dict[KEY_Album_Photos]!=[NSNull null]) {
            NSArray *pArray = dict[KEY_Album_Photos];
            NSMutableArray *tmpArray = [NSMutableArray array];
            for (NSDictionary *pDic in pArray) {
                PCPhotoModel *pModel = [[PCPhotoModel alloc] initWithDictionary:pDic];
                [tmpArray addObject:pModel];
            }
            _aPhotoArray = tmpArray;
        }
        
        //NSDate *cDate = [NSDate dateWithTimeIntervalSince1970:_cBeginTime];

        if (dict[KEY_Album_Date]!=[NSNull null]) {
            
            _aCreatAt = [dict[KEY_Album_Date] integerValue];
            NSDate *cDate = [NSDate dateWithTimeIntervalSince1970:_aCreatAt];
            _aDate = cDate;
            
            _aDay = [_aDate stringWithFormatter:@"dd"];
            NSString *dString= [_aDate stringWithFormatter:@"MM"];
            _aMonth = [self stringMonthWithString:dString];
        }
        
        if (dict[KEY_Album_UUID]!=[NSNull null]) {
            _aUUID = dict[KEY_Album_UUID];
        }
    }
    return self;
}

-(NSString *)stringMonthWithString:(NSString*)month
{
    if ([month isEqual:@"01"]) {
        return @"一月";
    }else if ([month isEqual:@"02"]){
        return @"二月";
    }else if ([month isEqual:@"03"]){
        return @"三月";
    }else if ([month isEqual:@"04"]){
        return @"四月";
    }else if ([month isEqual:@"05"]){
        return @"五月";
    }else if ([month isEqual:@"06"]){
        return @"六月";
    }else if ([month isEqual:@"07"]){
        return @"七月";
    }else if ([month isEqual:@"08"]){
        return @"八月";
    }else if ([month isEqual:@"09"]){
        return @"九月";
    }else if ([month isEqual:@"10"]){
        return @"十月";
    }else if ([month isEqual:@"11"]){
        return @"十一月";
    }else if ([month isEqual:@"12"]){
        return @"十二月";
    }
    return nil;
}

@end
